1. Field of the Invention
The present invention relates to a method and network device for fast look-up in a connection-oriented communication, and more particularly, to a method and network device utilizing an index and a way to reduce comparison times.
2. Description of the Prior Art
In the modern world of information, the need for wireless LAN increases day by day. Therefore, usage of wireless networks is getting widely spread. There are all kinds of network access protocols, where transmission control protocol (TCP) is one of the most important protocols. TCP is a transmission protocol that provides reliable, connection-oriented, and byte-stream oriented transmission services. Furthermore, user datagram protocol (UDP) is another important protocol. UDP is a transmission protocol that provides unreliable and not connection-oriented transmission services. Due to TCP always arranging pairs of IPs, they are combined into so-called TCP/IP protocol group.
Connection-oriented transmission handshakes with a host for confirming that the host is ready to receive data before starting to transfer data. After handshaking, the connection is built.
Please refer to FIG. 1. FIG. 1 is a diagram of a look-up mechanism in a connection-oriented communication according to the prior art. Assume that a first peer A wants to exchange data with a second peer B. The first peer A sends a request packet SYN to the second peer B. When the second peer B receives the request packet SYN, the second peer B sends a response packet SYN-ACK to the first peer A. When receiving the response packet SYN-ACK, the first peer A sends a response packet ACK to the second peer B. Therefore, the connection between the first peer A and the second peer B is built. Connection information is maintained in both the first peer A and the second peer B. As shown in FIG. 1, when the first peer A wants to send a packet 12 to the second peer B, the first peer A appends connection information into a header 14 of the packet 12 and sends the packet 12 to the second peer B. When receiving the packet 12, the second peer B checks the header 14 and uses connection information to run a hash function for getting an index. The packet 12 includes the header 14 and a payload 16. The header 14 includes a plurality of fields 15 to store data like source IP, destination IP, source port, and destination port. The second peer B includes a connection table 18, which includes a plurality of ways 17. Each way includes a plurality of fields 19 for storing data like source IP, destination IP, source port, and destination port. After finding out the index and comparing the content of the fields 19 with the fields 15, the second peer B finds a way 17 having the same contents as the fields 15.
Please refer to FIG. 2 and FIG. 1. FIG. 2 is a flow chart 20 of the look-up method in a connection-oriented communication according to the prior art. Flow chart 20 includes the following steps:
Step 202: Receiving a packet.
Step 204: Looking up a connection table.
Step 206: Using hash function to find out the index of the connection table.
Step 208: Comparing the connection information of each way.
Step 210: Checking the result of step 208.
Step 212: Checking if still other ways exist.
Step 214: Finding next way.
Step 216: Getting the connection information.
Step 218: The end.
In step 206, using the hash function includes a plurality of parameters such as data like source IP, destination IP, source port, and destination port. Running a hash function can get an index as the entrance of the connection table, but wastes time. In step 208, after finding the entrance of the connection table, the mechanism compares all connection information corresponding with the way (source IP, destination IP, source port, and destination port are fully identical).
Before building a connection between two peers, running a hash function and comparing ways several times is necessary. But running a hash function takes a lot of time. If a server connects with 64 k (or above) clients, the connection table is composed of 1024 indexes each having 64 ways. The prior art method needs to run a hash function and compare ways 64 times, wasting time and costs.